package com.bluesimon.wbf.utils;

import org.ume.school.modules.model.ErrorTag;

import com.bluesimon.wbf.IUser;
import com.bluesimon.wbf.Response;
import com.bluesimon.wbf.usercenter.enums.UserTypeEnum;

public class AuthValidate {
    public static <T> Response<T> checkAdmin(IUser user){
        Response<T> resp = null;
        if (user == null) {
            resp = new Response<T>();
            resp.setResultCode(ErrorTag.INVAILD_USER.getCode());
            resp.setResultMsg(ErrorTag.INVAILD_USER.getMessage());
        } 
        else if(user.getType()==null || user.getType().intValue() != UserTypeEnum.ADMIN.getValue()){
            resp = new Response<T>();
            resp.setResultCode(ErrorTag.NOT_ADMIN.getCode());
            resp.setResultMsg(ErrorTag.NOT_ADMIN.getMessage());
        }
        return resp;
    }
    
    public static <T> Response<T> checkUser(IUser user){
        Response<T> resp = null;
        if (user == null) {
            resp = new Response<T>();
            resp.setResultCode(ErrorTag.INVAILD_USER.getCode());
            resp.setResultMsg(ErrorTag.INVAILD_USER.getMessage());
        } 
        else if(user.getType()==null || user.getType().intValue() == UserTypeEnum.ADMIN.getValue()){
            resp = new Response<T>();
            resp.setResultCode(ErrorTag.IS_ADMIN.getCode());
            resp.setResultMsg(ErrorTag.IS_ADMIN.getMessage());
        }
        return resp;
    }
}
